package com.lpf.back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lpf.back.domain.Admin;
import com.lpf.back.mapper.AdminMapper;
import com.lpf.back.service.interfaces.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AdminServiceImp implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    public Admin getAdmin(String username){
        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username);
        return adminMapper.selectOne(wrapper);
    }

    @Override
    public int login(String username, String password) {
        System.out.println(username + ", " + password);
        Admin admin = getAdmin(username);
        if(admin == null){
            return 0;
        } else if(password.equals(admin.getPassword())) {
            return 1;
        }
        return 0;
    }

    @Override
    public Admin selectAdmin(String username) {
        return getAdmin(username);
    }
}
